package com.worley.argutils.config;

import java.util.List;

/**
 * 拷贝自(Spring Boot Redis自动配置)
 */
public class RedisProperties {

    /**
     * 连接工厂使用的DB
     */
    private int database = 0;

    /**
     * 以URL方式配置的信息，包含：host, port, password
     */
    private String url;

    /**
     * Redis服务的域名或IP
     */
    private String host = "localhost";

    /**
     * Redis服务的登录密码
     */
    private String password;

    /**
     * Redis服务的连接端口
     */
    private int port = 6379;

    /**
     * 是否启用SSL
     */
    private boolean ssl;

    /**
     * 连接超时毫秒值
     */
    private int timeout = 5000;

    private Pool pool;

    private Cluster cluster;

    public int getDatabase() {
        return this.database;
    }

    public void setDatabase(int database) {
        this.database = database;
    }

    public String getUrl() {
        return this.url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getHost() {
        return this.host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getPort() {
        return this.port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public boolean isSsl() {
        return this.ssl;
    }

    public void setSsl(boolean ssl) {
        this.ssl = ssl;
    }

    public void setTimeout(int timeout) {
        this.timeout = timeout;
    }

    public int getTimeout() {
        return this.timeout;
    }

    public Pool getPool() {
        return this.pool;
    }

    public void setPool(Pool pool) {
        this.pool = pool;
    }

    public Cluster getCluster() {
        return this.cluster;
    }

    public void setCluster(Cluster cluster) {
        this.cluster = cluster;
    }

    /**
     * Pool properties.
     */
    public static class Pool {

        /**
         * 池中允许的最大空闲连接
         */
        private int maxIdle = 10;

        /**
         * 池中要维护的最小空闲连接数
         */
        private int minIdle = 2;

        /**
         * 池中允许分配的最大连接数，负值表示不限制
         */
        private int maxActive = 100;

        /**
         * 池耗尽时，抛出异常之前应阻塞等待的最长毫秒数，负值表示无限期等待
         */
        private int maxWait = 3000;

        public int getMaxIdle() {
            return this.maxIdle;
        }

        public void setMaxIdle(int maxIdle) {
            this.maxIdle = maxIdle;
        }

        public int getMinIdle() {
            return this.minIdle;
        }

        public void setMinIdle(int minIdle) {
            this.minIdle = minIdle;
        }

        public int getMaxActive() {
            return this.maxActive;
        }

        public void setMaxActive(int maxActive) {
            this.maxActive = maxActive;
        }

        public int getMaxWait() {
            return this.maxWait;
        }

        public void setMaxWait(int maxWait) {
            this.maxWait = maxWait;
        }

        @Override
        public String toString() {
            return "Pool [maxIdle=" + maxIdle + ", minIdle=" + minIdle
                    + ", maxActive=" + maxActive + ", maxWait=" + maxWait + "]";
        }

    }

    /**
     * Cluster properties.
     */
    public static class Cluster {

        /**
         * 集群节点（host:port）列表，多个使用逗号分割，至少配置一个节点
         */
        private List<String> nodes;

        /**
         * 集群操作时最大重定向数
         */
        private Integer maxRedirects;

        public List<String> getNodes() {
            return this.nodes;
        }

        public void setNodes(List<String> nodes) {
            this.nodes = nodes;
        }

        public Integer getMaxRedirects() {
            return this.maxRedirects;
        }

        public void setMaxRedirects(Integer maxRedirects) {
            this.maxRedirects = maxRedirects;
        }

        @Override
        public String toString() {
            return "Cluster [nodes=" + nodes + ", maxRedirects=" + maxRedirects
                    + "]";
        }

    }

    @Override
    public String toString() {
        return "RedisProperties [database=" + database + ", url=" + url
                + ", host=" + host + ", password=" + password + ", port=" + port
                + ", ssl=" + ssl + ", timeout=" + timeout + ", pool=" + pool
                + ", cluster=" + cluster + "]";
    }

}
